#!/bin/bash

# 设置默认部署路径（可按需修改）
YAML_PATH="/programs/springboot-demo-k8s/order/k8s-deploy-springboot-order.yaml"

# 允许传参指定 YAML 文件路径
if [ $# -eq 1 ]; then
  YAML_PATH="$1"
fi

# 判断文件是否存在
if [ ! -f "$YAML_PATH" ]; then
  echo "❌ 部署文件不存在: $YAML_PATH"
  exit 1
fi

# 删除旧的资源
echo "🔄 正在删除已有部署..."
kubectl delete -f "$YAML_PATH" --ignore-not-found

# 创建新的部署
echo "🚀 正在部署新版本..."
kubectl apply -f "$YAML_PATH"

# 等待 Pod 启动
echo "⏳ 等待 Pod 启动中..."
sleep 3

kubectl get pods -n mate-app -o wide

echo "✅ k8s deploy success！"
exit 0